﻿Imports System.Data.SqlClient

Public Class adm_subCategory
    Inherits System.Web.UI.Page
    Private strCID As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strHtml As String = ""
        Dim strSCID, strSEname, strDes As String
        Dim HTMLString As String = ""
        Dim sSQL As String = ""
        Dim objfind As New GetData
        Dim objrd As SqlDataReader = Nothing
        Dim ps As New PreparedStatement(sSQL)
        Dim strErr As String = ""
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            strCID = Trim(Request("aid"))
            If Trim(Request("sdid")) = "del" Then
                strSCID = Trim(Request("sid"))
                sSQL = "delete from Sub_Category where Sub_Category_ID=@delId"
                ps.addParameter("delId", strSCID)
                ps.strSql = sSQL
                objfind.es(ps, strErr)
                If strErr = "" Then
                    result.InnerHtml = ""
                    result.InnerHtml = "<center><b><font color=""#FF0000""> Delete Sub Category Success！</font></b></center>"
                Else
                    result.InnerHtml = ""
                    result.InnerHtml = "<center><b><font color=""#FF0000"">Error！</font></b><p>" & strErr & "</p></center>"
                End If
            End If

            sSQL = "select * from Sub_Category where Category_ID=@id"
            ps.addParameter("id", strCID)
            ps.strSql = sSQL
            Dim conn As SqlConnection = objfind.getConn()

            objrd = objfind.dr(ps, strErr, conn, objrd)
            If objrd.HasRows Then
                strHtml += "<table class='minorbox' cellspacing='1' width='100%' border=""0""  style=""background-color:#3399FF"">"
                strHtml += "<tr	><td class='gridheader'  style=""background-color:#AACCFF"">Sub Category ID</td>"
                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Sub Category Name</td>"
                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Description</td>"
                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Operation</td>"
                While (objrd.Read())
                    strSCID = objrd("Sub_Category_ID").ToString
                    strSEname = objrd("Sub_Category_Name").ToString
                    strDes = objrd("Description").ToString
                    HTMLString = HTMLString & vbCr & vbTab & vbTab & "<tr>"
                    HTMLString = HTMLString & "<td valign=""top""  style=""background-color:#FFF"">" & strSCID & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & strSEname & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & strDes & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF""><a href=""adm_editSubCategory.aspx?aid=" & strCID & "&sid=" & strSCID & """>Edit</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=""adm_subCategory.aspx?aid=" & strCID & "&sid=" & strSCID & "&sdid=del"">Delete</a></td>"
                End While
                HTMLString = HTMLString & "</table>"
                strHtml += HTMLString
            Else
                strHtml = "No Sub Category was found"
            End If
            objfind.closeConn(conn)

            searchResult.InnerHtml = strHtml
        Else
            Response.Redirect("../adm_login.aspx")
        End If
    End Sub

    Private Sub btnCreate_Click(sender As Object, e As System.EventArgs) Handles btnCreate.Click
        Response.Redirect("adm_addSubCategory.aspx?aid=" & strCID & "")
    End Sub
End Class